import { createRouter,createWebHashHistory,createMemoryHistory } from "vue-router";

const routers = [
    {
        path:"/",
        redirect: { name: 'one' }
    },
    {
        path:"/comment",
        name:"comment",
        component:()=>import('../components/Comment1.vue')
    },
    {
        path:"/one",
        name:"one",
        component:()=>import('../components/ButtonCounter.vue')
    },
    {
       path:"/two",
       name:"two",
       component:()=>import('../components/ButtonCounter2.vue'),
       children:[
        {
            path:"/three",
            name:"three",
            component:()=>import('../components/ButtonCounter3.vue'),
            meta:{isAuth:true},
        },
       ],
    }
];

const router = createRouter({
    history: createWebHashHistory(),
    routes: routers,
  })

  router.beforeEach((to,from,next)=>{
    if(to.meta.isAuth){
        if(localStorage.getItem('token')==='1'){
            next();
        }else{
            alert("请先登入");
        }
    }else{
        next();
    }
  });

export default router;